package file_io;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;

public class FileIOMain {

	private ArrayList<String> outputList = new ArrayList<String>();

	FileIOMain() {
		outputList.add("学号：152040135112");
		outputList.add("姓名：毛安淳 ");
		outputList.add("我爱用大宝");
		for (int i = 0; i < 1000; i++) {
			String morning = "Good Morning";
			outputList.add(morning + i);
		}
	}

	public void readFile(String file_path) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file_path), "GBK"));
		String lineText = null;
		while ((lineText = br.readLine()) != null) {
			System.out.println(lineText);
		}
		br.close();
	}

	public void writeFile(String file_path) throws IOException {
		File file;
		FileWriter fw;
		PrintWriter pw;

		file = new File(file_path);
		if (!file.exists()) {
			file.createNewFile();
		}
		fw = new FileWriter(file);
		pw = new PrintWriter(fw);

		for (String str : outputList) {
			pw.write(str + "\n");
		}

		pw.close();
	}

	public static void main(String[] args) throws IOException {
		FileIOMain io = new FileIOMain();
		io.readFile("D:/hw3_input.txt");
		io.writeFile("d:/hw3_output.txt");
	}

}
